#include <thread>
#include <memory>
#include <functional>
#include <iostream>
#include <unistd.h>
#include "mutex.h"

class CountNumber
{
    private:
        int number;
        utils::MutexLock mutex;
    public:
        CountNumber() : mutex()
        {
            number = 0;
        }
        void Incrms(const int n, const std::string info)
        {
            
            for (int i = 0; i < n; i++)
            {
                utils::MutexLockGuard guard(mutex);
                ++number;
            }
           
        }
        void Down(const int n, const std::string info)
        {
           
            for (int i = 0; i < n; i++)
            {
                 utils::MutexLockGuard guard(mutex);
                --number;
            }
        }
        int PrintNum()
        {
            return number;
        }
};

int main()
{
    CountNumber foo;
    std::thread work1(std::bind(&CountNumber::Incrms, &foo, 10000, "hello "));
    std::thread work2(std::bind(&CountNumber::Down, &foo, 10000, "word"));
   
    work1.join();
    work2.join();
    std::cout << foo.PrintNum() << std::endl;
    return 1;

}